home *** CD-ROM | disk | FTP | other *** search
- /*
- All Shapes.c
-
- "All Shapes" creates, manipulates, and draws all of the QuickDraw™ GX primitive shapes. As each shape is created,
- it is added to "thePage". This shape represents the contents of the window. To create a shape, the user
- needs to "click" within the content region of the window.
-
- This file contains the calls that an application needs to make the "graphics shell" work correctly.
-
- ©1992 - 1993 Apple Computer, Inc.
- All rights reserved.
-
- 3/22/94 - dmh - Corrected GXSetShapeAttributes usage to preserve old attributes.
- 8/24/94 - dmh - Universalized.
- */
-
- #include <StdIO.h>
-
- #include <events.h>
- #include <memory.h>
- #include <windows.h>
-
- #include "font library.h"
- #include "graphics libraries.h"
- #include "graphics toolbox.h"
- #include "graphics debugging.h"
- #include "qd library.h"
- #include "PrintingMessages.h"
- #include "PrintingManager.h"
-
- #include "graphics shell.h"
-
-
- /** Set up the title and size of the window **/
- Str255 gWindowTitle = "\p Shapes...";
- Rect gWindowQDRect = {50, 15, 475, 575};
-
- /**
- If gDebugging = TRUE, graphics library errors and notices will be posted. This functionality will only work with
- the "debugging" version of the QuickDraw GX init. If this version of the init is not installed, nothing bad will happen,
- but these functions will not work.
- **/
- Boolean gDebugging = true;
-
-
- /** Set "gGiveMeValidation" to TRUE, if you will receive run-time validation. **/
- Boolean gGiveMeValidation = true;
-
-
- /**
- gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
- in main () within graphics shell.c. You can determine the amount of graphics heap required by using GraphicsBug.
- I'm giving it 600K, since we need abunch if we have several windows open.
- **/
- long gGraphicsHeapSize = 600;
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
- //
- // In this function we create and gxInitialize the the private document structure for a new window. This
- // structure contains the print job and the shape which is drawn in the window. We store this data in
- // a handle and hang it off the window's refCon field for easy retrieval. By doing this, rather than using
- // globals, we can create many windows containing unique print jobs and shapes.
- //
- OSErr DoInitialization(wind)
- WindowPtr wind;
- {
- OSErr err;
- gxJob docJob;
- gxShape docPage;
- TH_Doc windDoc;
-
- // Create the page shape. We set the unique items attribute to make sure that each item added to the
- // picture has a unique reference. If this attribute was not set, we would not see all six S's rotated.
- // We would only see the last "S" rotated; not all 6 pieces.
-
- docPage = GXNewShape(gxPictureType);
- GXSetShapeAttributes(docPage, GXGetShapeAttributes(docPage)|gxUniqueItemsShape);
-
- // Create a print job for this document. This will be the same as the system default until the user
- // goes through the dialogs for Page Setup or Print…
-
- err = GXNewJob(&docJob);
-
-
- // If there are no errors, create a handle the size of our document structure and store the print job and page shape
- // in it. Store the handle in the window's refCon field so that we can get at it. (Note that the utility routines
- // "GetDocJob" and "GetDocShape" can be used to do this easily.
-
- if (!err)
- {
- windDoc = (TH_Doc) NewHandleClear(sizeof(T_Doc));
-
- if (!windDoc)
- err = MemError();
- else
- {
- (*windDoc)->docJob = docJob;
- (*windDoc)->docPage = docPage;
- ((WindowPeek) wind)->refCon = (long) windDoc;
- }
-
- // Now install our application override for PrintingEvent so that we can
- // support the new movable-modal printing dialog boxes.
-
- GXInstallApplicationOverride(docJob, gxPrintingEvent, NewGXPrintingEventProc(MyPrintingEventOverride));
- }
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
- //
- // Draw the contents of the window.
- //
- void DoDraw(wind)
- WindowPtr wind;
- {
- GXDrawShape (GetDocShape(wind));
- }
-
-
- /*------ CreateSampleImage ----------------------------------------------------------------------------*/
- //
- // This function creates primitive shapes and adds them to the window's page shape.
- //
- void CreateSampleImage(WindowPtr wind)
- {
- gxShape thePage;
- gxShape theLine;
- gxLine lineData = {ff(25), ff(25), ff(125), ff(125)};
- gxShape theRect;
- gxRectangle rectData = {ff(25), ff(25), ff(75), ff(75)};
- gxShape theCurve;
- gxCurve curveData = {ff(25), ff(25), ff(275), ff(75), ff(125), ff(125)};
- gxShape thePath;
- long tripleEightData[] = { 1 /* # of contours */,
- 6 /* # of points */,
- 0xff000000,
- 0, 0, // the points
- ff(75), 0,
- ff(5), ff(50),
- ff(75), ff(100),
- 0, ff(100),
- ff(75), ff(50)};
- gxShape theText;
- gxRectangle theTextBounds;
- gxColor textColor;
- fixed x,y;
- short loop;
- gxShape thePolygon;
- long starData[] = { 1, /** number of contours **/
- 5 , /** number of points **/
- ff(60), 0, ff(90), ff(90), ff(0), ff(30), ff(120), ff(30), ff(0), ff(90)}; /** the points **/
- gxShape theBitmap;
-
- // Retrieve the page shape so we can add to it.
-
- thePage = GetDocShape(wind);
-
-
- // Create a line
-
- theLine = GXNewLine (&lineData);
-
- AddToShape(thePage, theLine);
- GXDisposeShape(theLine);
-
-
- // Create a rectangle which is: red & is draw with it's frame.
-
- theRect = GXNewRectangle(&rectData);
- SetShapeCommonColor (theRect, red);
- GXSetShapeFill (theRect, gxClosedFrameFill);
- GXMoveShapeTo (theRect, ff(150), ff(25));
-
- AddToShape(thePage, theRect);
- GXDisposeShape(theRect);
-
-
- // Create a curve which has: a 3.25 pen thickness
-
- theCurve = GXNewCurve(&curveData);
-
- // The fl marco converts floating gxPoint #'s to fixed gxPoint.
- GXSetShapePen(theCurve, fl(3.25));
- GXMoveShapeTo (theCurve, ff(210), ff(25));
-
- AddToShape(thePage, theCurve);
- GXDisposeShape(theCurve);
-
-
- // Create apath which has: a 2 pen thickness, it's gxColor is green, and it's drawn with it's frame
-
- thePath = GXNewPaths((gxPaths *) tripleEightData);
- GXSetShapeFill (thePath, gxClosedFrameFill);
- GXSetShapePen(thePath, ff(2));
- SetShapeCommonColor (thePath, green);
-
- GXMoveShapeTo (thePath, ff(390), ff(25));
-
- AddToShape(thePage, thePath);
- GXDisposeShape(thePath);
-
-
- // Create a character S which is: colored in hsv space and it is rotated 15 degrees - six times via the left bottom corner.
- // Create the text, set the gxFont size, and set the gxFont name
-
- theText = GXNewText(1,(unsigned char*)"S", nil);
- SetShapeCommonFont(theText, timesFont);
- GXSetShapeTextSize(theText, ff(200));
- GXMoveShapeTo (theText, ff(25), ff(275));
- GXSetShapeAttributes (theText, gxMapTransformShape);
-
- // Create an hsv color space and set up the initial colors
-
- textColor.space = gxHSVSpace;
- textColor.profile = nil;
- textColor.element.hsv.hue = 0x7400;
- textColor.element.hsv.saturation = 0xFFFF;
- textColor.element.hsv.value = 0xFFFF;
-
- // Get the bounds of "theText" and determine the bottom left corner
-
- GXGetShapeBounds(theText, 0L, &theTextBounds);
- x = theTextBounds.left;
- y = theTextBounds.bottom;
-
- // Rotate "theText" 15 degrees - 6 times. Add each letter to the picture.
-
- for (loop = 0; loop < 6; loop++) {
- GXSetShapeColor(theText, &textColor);
- GXRotateShape(theText, ff(15), x, y);
-
- AddToShape(thePage, theText);
-
- textColor.element.hsv.hue += 0x0940;
- }
-
- GXDisposeShape(theText);
-
-
- // Create a polygon which has the following features: yellow, drawn with a pen = 3, and skew it in the vertical direction by 0.5
-
- thePolygon = GXNewPolygons((gxPolygons *) starData);
- GXSetShapeFill(thePolygon, gxEvenOddFill);
- GXSetShapePen (thePolygon, ff(3));
- SetShapeCommonColor (thePolygon, yellow);
- GXMoveShapeTo (thePolygon, ff(240), ff(110));
- GXSkewShape(thePolygon, 0, fl(0.5), 0, 0);
-
- AddToShape(thePage, thePolygon);
- GXDisposeShape(thePolygon);
-
-
- // Retrieve a bitmap from the resource fork and skew it in the horizontal direction by 2.
-
- theBitmap = GetPixMapShape(128);
- GXValidateShape (theBitmap);
-
- GXSkewShape(theBitmap, ff(2), 0, 0, 0);
- GXMoveShapeTo (theBitmap, ff(290), ff(190));
-
- AddToShape(thePage, theBitmap);
- GXDisposeShape(theBitmap);
-
-
- // Invalidate the window's portRect so that everything gets updated.
-
- SetPort(wind);
- InvalRect(&wind->portRect);
- }
-
-
- /*------ DoCreateNew ---------------------------------------------------------------------------------*/
- //
- // This routine is called when a window needs to be created.
- //
- OSErr DoCreateNew(void)
- {
- OSErr err;
- WindowPtr wind;
-
- /** Create a window, attach a default gxViewPort to it, create and gxInitialize our private data for it, and
- /** add a sample image to its page shape. **/
-
- wind = NewWindow(nil, &gWindowQDRect, gWindowTitle, true, noGrowDocProc, (WindowPtr)-1L, true, 0L);
-
- if (!wind)
- err = MemError();
- else
- {
- SetDefaultViewPort(GXNewWindowViewPort(wind));
- err = DoInitialization(wind);
- }
-
- CreateSampleImage(wind);
- return err;
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
- //
- // This routine is called when a window needs to be disposed of.
- //
- void DoDispose(wind)
- WindowPtr wind;
- {
- TH_Doc doc;
-
- /**
- You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- can turn notices on in this file by setting gDebugging = TRUE (above).
- **/
-
- doc = (TH_Doc) GetWRefCon(wind); // Remember, this is where we stored our private data.
-
- GXDisposeShape(GetDocShape(wind)); // Dispose of this doc's shape.
- GXDisposeJob(GetDocJob(wind)); // Dispose of this doc's print job.
- DisposHandle((Handle) doc); // Dispose of our private data.
-
- DisposeWindow(wind); // Dispose of the window.
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
- //
- // This routine is called to do things while we're idling through tthe event loop.
- //
- void DoIdle(WindowPtr wind)
- {
- }
-
-